package com.baigt.jvm.base;

import java.util.UUID;

/**
 * 类功能描述:
 * //move Variable2 static code  static variable b  top
 * // del Variable2's class?
 * <p>
 * Variable3
 * 删除.class文件试试？
 *
 * @author baigt
 * @version V1.0
 * @since 2019-06-27 14:09
 */
public class _02BaseTest {
    public static void main(String[] args) {
        Variable variable = new Variable();
        System.out.println(variable);
        System.out.println(Variable2.b);
        System.out.println(Variable3.str);
        System.out.println(Singleton.getInstance());
    }
}

class Variable {
    private int a;
    private int b = 1;

    public Variable() {
        System.out.println(b);
        a++;
        b++;
    }

    @Override
    public String toString() {
        return "Variable{" + "a=" + a + ", b=" + b + '}';
    }
}

class Variable2 {
    public static int a;

    static {
        b = 2;
        System.out.println("Variable2 init");
    }

    public static int b = 1;
}

class Singleton {
    public static int val1;
    public static Singleton instance = new Singleton();
    public static int val2 = 0;
    private Singleton(){
        val1++;
        val2++;
    }
    public static Singleton getInstance(){
        return instance;
    }

    @Override
    public String toString() {
        return "val1:"+val1+",val2:"+val2;
    }
}

class Variable3 {
    public static final String str = "hello ricky";

    static {
        // 会打印么
        System.out.println("Variable3 init");
    }
}

class Variable4 {
    public static final String str = UUID.randomUUID().toString();

    static {
        // 会打印么？
        System.out.println("Variable4 init");
    }
}
